package com.feitian.plugin.config;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;

/**
 *@author MACHENIK
 *@date   2018年11月6日
 *@feature 创建流程引擎
 *@desc 
 *
 */
public class ProcessEngineConfig {
	
	/**
	 * @author MACHENIKE
	 * @date 17点02分
	 * @feature  创建流程引擎（通过配置创建）
	 */
	public static ProcessEngine getProcessEngine() {
		ProcessEngine processEngine=null;
		//创建单利模式的引擎配置对象
		ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
		processEngineConfiguration.setJdbcDriver("com.mysql.jdbc.driver");
		processEngineConfiguration.setJdbcUrl("");
		processEngineConfiguration.setJdbcUsername("");
		processEngineConfiguration.setJdbcPassword("");
		/**
		 
		    public static final String DB_SCHEMA_UPDATE_FALSE = "false"; #检查数据库表的版本和依赖库的版本，如果版本不匹配就抛出异常

  			public static final String DB_SCHEMA_UPDATE_CREATE_DROP = "create-drop"; #构建流程引擎时创建数据库表，关闭流程引擎删除这些表

  
  			public static final String DB_SCHEMA_UPDATE_TRUE = "true"; #构建流程引擎时，执行检查，如果需要执行更新，不存在就创建

		 */
		processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
		
		processEngine = processEngineConfiguration.buildProcessEngine();
		return processEngine;
	}
	
	/**
	 *
	 * @return
	 *@author MACHENIKE
	 *@date 2018年11月6日
	 *@feature 通过配置文件加载引擎配置对象
	 */
	public static ProcessEngine getProcessEngineResources() {
		ProcessEngine processEngine=null;
		processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine();
		return processEngine;
	}
	
	
	public static ProcessEngine getProcessEngineDefault() {
		ProcessEngine processEngine = null;
		processEngine = ProcessEngines.getDefaultProcessEngine();
		
		return  processEngine;
	}
}
